package com.practice.xw.handler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author ：xiongwei
 * @date ：Created in 2021/7/20 23:41
 */
public class ProxyHandler implements InvocationHandler {

    private Object object;
    public ProxyHandler(Object object){
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Before invoke "  + method.getName());
        Object methodObject = null;
        for (int i = 0; i < 5; i++) {
            try{
                methodObject = method.invoke(object, args);
            }catch (Exception e){
                System.out.println("invoke = "  + e.getMessage());
            }
        }
        System.out.println("After invoke " + method.getName());
        return methodObject;
    }

}
